class Segment extends egret.Sprite {
    private color: number
    private segmentWidth: number
    private segmentHeight: number

    private vx: number = 0
    private vy: number = 0
    public constructor(segmentWidth: number, segmentHeight: number, color: number = 0xFFFFFF) {
        super()
        this.segmentWidth = segmentWidth
        this.segmentHeight = segmentHeight
        this.color = color
        this.init()
    }

    public init() {
        this.graphics.beginFill(this.color)
            this.graphics.drawRoundRect(
                -this.segmentHeight / 2,
                -this.segmentHeight / 2,
                this.segmentWidth + this.segmentHeight,
                this.segmentHeight,
                this.segmentHeight,
                this.segmentHeight)
        this.graphics.endFill()

        // 绘制两个轴栓
        this.graphics.lineStyle(1.01)
        this.graphics.beginFill(0x000000)
            this.graphics.drawCircle(0, 0, 2)
            this.graphics.drawCircle(this.segmentWidth, 0, 2)
        this.graphics.endFill()
    }

    public getPin(): egret.Point {
        let angle = this.rotation * Math.PI / 180
        let xPos = this.x + Math.cos(angle) * this.segmentWidth
        let yPos = this.y + Math.sin(angle) * this.segmentWidth
        return new egret.Point(xPos, yPos)
    }
}